package pl.register.android.task;

import pl.register.android.util.time.DateUtil;

import java.io.Serializable;
import java.util.Date;

/**
 * @author Mateusz Strzelecki
 * @since 2013-05-02
 */
public class Task implements Serializable, Comparable<Task> {

    private Long id;

    private String title;

    private String message;

    private Date creationDate;

    public static Task nullObject() {
        return new Task(null, "", "", new Date());
    }

    public Task(Long id, String title, String message, Date creationDate) {
        this.id = id;
        this.title = title;
        this.message = message;
        this.creationDate = creationDate;
    }

    public boolean isPersisted() {
        return id != null;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public Date getCreationDate() {
        return creationDate;
    }

    public String getCreationDateInString() {
        return DateUtil.getDateInFormat("dd.MM.yyyy", creationDate, "BRAK");
    }

    public Long getCreationDateInMs() {
        if (creationDate != null) {
            return creationDate.getTime();
        }
        return null;
    }

    @Override
    public int compareTo(Task toCompare) {
        return toCompare.getCreationDate().compareTo(creationDate);
    }

    @Override
    public String toString() {
        return "Task{" +
                "id=" + id +
                ", title='" + title + '\'' +
                ", message='" + message + '\'' +
                ", creationDate=" + creationDate +
                '}';
    }
}
